db <- db <- dbConnect(RSQLite::SQLite(),dbname= "../COVID-19-DB/OURWORLD.sqlite3")
portugal <- dbGetQuery(db,"select * from OWID where location ='Portugal'")
portugal$date <- as.Date(portugal$date)
## Clean Data
portugal <- janitor::clean_names(portugal)
portugal <- janitor::remove_empty(portugal,which = c("cols","rows"))
portugal$date <- as.Date(portugal$date)
dim(portugal)
## [1] 625 60
Portugal : Analysis of Cases, Deaths and Vaccination Rate
# Calculate Vaccination Rate i.e Poeple Vaccinate / Population
portugal<- portugal %>% mutate(vacc_rate = people_vaccinated/population)
# Calculate 14 day moivng average
portugal$avg_cases <- ma(portugal$new_cases,14,centre = TRUE)
portugal$avg_deaths <- ma(portugal$new_deaths,14,centre = TRUE)
Plot of Daily Cases and Daths w/ 14 Day Moving Avearge
p1 <- portugal %>% ggplot() +
geom_line(aes(x=date,y=new_cases,col="Daily Cases"),lwd=1) +
geom_line(aes(x=date,y=avg_cases,col="Moving Avg."),lwd=1) +
labs(title = "Daily cases + 14 Day Moving Average",y="Daily Cases",x="Date")
ggplotly(p1)
p2 <- portugal %>% ggplot() +
geom_line(aes(x=date,y=new_deaths,col="Daily Deaths"),lwd=1) +
geom_line(aes(x=date,y=avg_deaths,col="Moving Avg."),lwd=1) +
labs(title = "Daily Deaths + 14 Day Moving Average",y="Daily Deaths",x="Date")
ggplotly(p2)
Cases and Deaths by Week
p3 <- portugal %>% summarize_by_time(.by ="week",value=sum(new_cases)) %>% na.omit() %>% ggplot(aes(x=date,y=value)) + geom_col() +
labs(title = "Weekly Cases")
## .date_var is missing. Using: date
ggplotly(p3)
p4 <- portugal %>% summarize_by_time(.by ="week",value=sum(new_deaths)) %>% na.omit() %>% ggplot(aes(x=date,y=value)) + geom_col() +
labs(title = "Weekly Deaths")
## .date_var is missing. Using: date
ggplotly(p4)
Cases and Deaths by Month
p5 <- portugal %>% summarize_by_time(.by ="month",value=sum(new_cases)) %>% na.omit() %>% ggplot(aes(x=date,y=value)) + geom_col() +
labs(title = "Monthly Cases")
## .date_var is missing. Using: date
ggplotly(p5)
portugal %>% summarize_by_time(.by ="month",value=sum(new_deaths)) %>% na.omit() %>% ggplot(aes(x=date,y=value)) + geom_col() +
labs(title = "Monthly Deaths")
## .date_var is missing. Using: date
